<template>
  <div v-loading="loading" class="app-container">
    <div class="search-box">
      <div class="search-form">
        <el-form ref="searchForm" :inline="true" :model="searchForm">
          <el-form-item label="编码" prop="key">
            <el-input v-model="searchForm.key" maxlength="32" autocomplete="off" />
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="searchForm.name" maxlength="100" autocomplete="off" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
            <el-button icon="el-icon-remove-outline" title="重置" @click="resetSearchForm" />
          </el-form-item>
        </el-form>
      </div>

    </div>

    <el-table
      ref="multipleTable"
      stripe
      :data="tableData"
      border
      class="table"
    >
      <el-table-column prop="key" label="编码" />
      <el-table-column prop="name" label="名称" />
      <el-table-column prop="memo" label="说明" />
      <el-table-column prop="value" label="值" />
      <el-table-column prop="isSystem" label="是否系统定义">
        <template slot-scope="scope">
          <span>{{ scope.row.isSystem |booleanFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160" align="left">
        <template slot-scope="scope">
          <el-button v-if="!scope.row.isSystem" type="text" icon="el-icon-edit" @click="handleEdit(scope.row.key)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--表单组件-->
    <eForm ref="eform" />
  </div>
</template>

<script>
import request from '@/utils/request'

import eForm from './form'
export default {
  name: 'SysParams',
  components: { eForm },
  data() {
    return {
      loading: true,
      downloadLoading: false,
      orderByClause: null,
      tableData: [],
      searchForm: {
        key: '',
        name: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取数据
    getList() {
      this.loading = true
      const param = {}
      if (this.orderByClause && this.orderByClause.trim() !== '') {
        param.orderByClause = this.orderByClause
      }
      this.copyNotBlankField(this.searchForm, param)
      request({ url: '/sys/sysparams/findList', method: 'post', data: param })
        .then(res => {
          this.loading = false
          this.tableData = res
        })
        .catch(e => {
          this.loading = false
          this.$message.error('查询出错')
        })
    },
    onSearch() {
      this.getList()
    },
    resetSearchForm() {
      this.$refs['searchForm'].resetFields()
    },
    handleEdit(id) {
      this.$refs.eform.edit(id)
    }

  }
}
</script>
